<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            let tree = {
                val: 1,
                left: {
                    val: 2,
                    left: {
                        val: 4,
                    },
                    right: {
                        val: 5,
                    },
                },
                right: {
                    val: 3,
                    left: {
                        val: 6,
                    },
                    right: {
                        val: 7,
                    },
                },
            }
            /* 
            迭代法：实现前序遍历  以栈的方式，从右到左的推入栈中  这样弹出的时候才是中左右 
            */
            /* function preOrderByStack(root) {
                if (!root) return []
                let res = []
                let stack = [root]
                while (stack.length) {
                    let node = stack.pop()
                    res.push(node.val)
                    if (node.right) {
                        stack.push(node.right)
                    }
                    if (node.left) {
                        stack.push(node.left)
                    }
                }
                return res
            }
            preOrderByStack(tree) */
            let res = []
            res.push(undefined)
            let node = res.pop()
            console.log(node.left)
        </script>
    </body>
</html>
